home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
utils
/
belltst2.lzh
/
BELLTEST.C
next >
Wrap
C/C++ Source or Header
|
1990-04-05
|
7KB
|
376 lines
#include <aes.h>
#include <stdio.h>
#include <stdlib.h>
#include <tos.h>
#include <string.h>
#include <mydefs.h>
#include "strins.c"
#include "belltest.h"
#include "belltstr.c"
void mess(char *c)
{
char a[40];
graf_mouse(ARROW,0);
strcpy(a,"[3][");
strcat(a,c);
strcat(a,"][OK]");
form_alert(1,a);
graf_mouse(POINT_HAND,0);
}
/*******************************
Select a file
*******************************/
int fileselect(
char *s,
char *ext)
{
char p[64];
int n;
int drv;
drv = Dgetdrv();
Dgetpath(p,0);
if (p[0] != '\\') strinc(p,0,'\\');
strins(p,0,"A:");
while (drv > 0)
{
--drv;
++p[0];
}
if (p[strlen(p)-1] != '\\') strcat(p,"\\");
strcat(p,ext);
graf_mouse(ARROW,0);
fsel_input(p,s,&n);
graf_mouse(POINT_HAND,0);
if (strrchr(p,'\\') != strchr(p,'\\'))
*(strrchr(p,'\\')) = 0x0;
else
*(strrchr(p,'\\')+1) = 0x0;
while (*p > 'A')
{
--p[0];
++drv;
}
Dsetdrv(drv);
Dsetpath(p+2);
return(n);
}
void dial_draw(
int box_ind,
int obj )
{
int x1,y1;
OBJECT *redraw;
redraw = &rs_object[rs_trloc[box_ind]+obj];
objc_offset(rs_trindex[box_ind],obj,&x1,&y1);
objc_draw(rs_trindex[box_ind],1,10,x1,y1,redraw->ob_width,redraw->ob_height);
}
void erase_dialog(
int x,
int y,
int w,
int h )
{
int sx,sy;
sx=x+(w/2);
sy=y+(h/2);
form_dial(FMD_SHRINK,sx,sy,0,0,x,y,w,h);
form_dial(FMD_FINISH,sx,sy,0,0,x,y,w,h);
}
void draw_dialog(
int box_ind,
int *x,
int *y,
int *w,
int *h,
char draw )
{
int sx,sy;
form_center(rs_trindex[box_ind],x,y,w,h);
sx=*x+(*w/2);
sy=*y+(*h/2);
form_dial(FMD_START,sx,sy,0,0,*x,*y,*w,*h);
form_dial(FMD_GROW,sx,sy,0,0,*x,*y,*w,*h);
if (draw) objc_draw(rs_trindex[box_ind],0,10,*x,*y,*w,*h);
}
void unselect(
int box,
int item)
{
rs_object[rs_trloc[box]+item].ob_state &= UNSELECT;
}
int selected(
int box,
int item)
{
return(rs_object[rs_trloc[box]+item].ob_state & SELECTED);
}
int exit_dialog(
int box_ind,
int x,
int y,
int w,
int h,
int draw )
{
int e;
if (draw) objc_draw(rs_trindex[box_ind],0,10,x,y,w,h);
e = form_do(rs_trindex[box_ind],0);
unselect(box_ind,e);
dial_draw(box_ind,e);
return(e);
}
void putspeed(char c)
{
int i;
for(i=MAINSPD1;i<=MAINSPD5;i++)
if ((rs_object[i].ob_state & SELECTED)!=0)
{
if (c != *rs_object[i].ob_spec.free_string)
rs_object[i].ob_state &= UNSELECT;
}
else
{
if (c == *rs_object[i].ob_spec.free_string)
rs_object[i].ob_state |= SELECTED;
}
}
char getspeed(void)
{
int i;
char c='3';
for(i=MAINSPD1;i<=MAINSPD5;i++)
if ((rs_object[i].ob_state & SELECTED)!=0)
c = *rs_object[i].ob_spec.free_string;
return(c);
}
int main()
{
int x,y,w,h;
int choice,flag,fd;
static char *ext="*.SND";
static COMMAND line={0,"0 BELLTEST.SND"};
static COMMAND lin2={0,"1 BELLTEST.SND"};
char *buf,*buf2,*file,*fil2;
DTA *dta;
long l,l2;
static char *newb="\0C:\\AUTO\\NEWBELL.PRG";
long *screen;
long cnt;
long *scrbuf;
long b1,b2;
int slc,sld,slr;
int loaded;
int saving;
/* INITIALIZE GEM */
appl_init();
fix_objects();
/* APPLICATION ROUTINES */
graf_mouse(POINT_HAND,0);
flag=0;
if (Fsfirst("NEWBELL.PRG",0)<0)
{
++flag;
if (Fsfirst("C:\\AUTO\\NEWBELL.PRG",0)<0)
{
++flag;
if (Fsfirst("A:\\AUTO\\NEWBELL.PRG",0)<0)
{
mess("NEWBELL.PRG NOT FOUND");
++flag;
}
else
strcpy(newb,"A:\\AUTO\\NEWBELL.PRG");
}
else
strcpy(newb,"C:\\AUTO\\NEWBELL.PRG");
}
else
strcpy(newb,"NEWBELL.PRG");
if (flag!=3)
{
draw_dialog(MAINDIAL,&x,&y,&w,&h,1);
sld = rs_object[rs_trloc[MAINDIAL]+MAINSLID].ob_x;
file = line.command_tail+2;
fil2 = lin2.command_tail+2;
buf = NULL;
slc = sld;
loaded = 0;
choice=0;
while(choice!=MAINQUIT)
{
saving=0;
choice = exit_dialog(MAINDIAL,x,y,w,h,0);
switch(choice)
{
case MAINLOAD:
erase_dialog(x,y,w,h);
if (fileselect(file,ext))
{
if (Fsfirst(file,0)>=0)
{
dta = Fgetdta();
l = dta->d_length;
if (buf!=NULL)
free(buf);
buf=malloc(l+16);
fd=Fopen(file,READ);
if (fd>=0)
loaded=1;
Fread(fd,l,buf);
Fclose(fd);
if ((*buf<6)&&(*buf>0))
putspeed(*buf+'0');
slc=sld;
rs_object[rs_trloc[MAINDIAL]+MAINSLID].ob_x=slc;
dial_draw(MAINDIAL,MAINBACK);
}
}
draw_dialog(MAINDIAL,&x,&y,&w,&h,1);
break;
case MAINSAVE: saving = 1;
case MAINPLAY:
if (loaded)
{
scrbuf=malloc(32768L);
if (scrbuf!=NULL)
{
graf_mouse(M_OFF,0);
screen=(long *)Physbase();
for(cnt=0;cnt<8192L;cnt++)
{
*(scrbuf+cnt)=*(screen+cnt);
*(screen+cnt)=0L;
}
}
line.length = strlen(line.command_tail);
lin2.length = strlen(lin2.command_tail);
*line.command_tail = getspeed();
*lin2.command_tail = getspeed();
*buf = getspeed() - '0';
if (slc==sld)
{
fd=Fopen(file,WRITE);
Fwrite(fd,l,buf);
Fclose(fd);
if (!saving)
Pexec(0,newb,&line,NULL);
}
else
{
if (slc<sld)
{
slr=slc+1;
l2=l+(l/slr)+slr;
}
else
{
slr=((2*sld)+2)-slc;
l2=l-(l/slr)+slr;
}
buf2=malloc(l2);
if (buf2!=NULL)
{
for(b1=0,b2=0;b1<l;b1++)
{
*(buf2+b2)=*(buf+b1);
++b2;
if (((b1+1)%slr)==0)
{
if (slc>sld)
--b2;
else
{
*(buf2+b2)=*(buf+b1);
++b2;
}
}
}
fd=Fcreate(fil2,0);
Fclose(fd);
fd=Fopen(fil2,WRITE);
Fwrite(fd,l2,buf2);
Fclose(fd);
if (!saving)
{
Pexec(0,newb,&lin2,NULL);
Fdelete(fil2);
}
else
{
Fdelete(file);
Frename(0,fil2,file);
}
free(buf2);
}
else
{
mess("Not enough memory!");
mess("Center slider?");
}
}
if (scrbuf!=NULL)
{
for(cnt=0;cnt<8192L;cnt++)
*(screen+cnt)=*(scrbuf+cnt);
free(scrbuf);
graf_mouse(M_ON,0);
graf_mouse(POINT_HAND,0);
}
}
else
mess("Load .SND first!");
break;
case MAINLESS:
if (slc>0)
{
--slc;
rs_object[rs_trloc[MAINDIAL]+MAINSLID].ob_x=slc;
dial_draw(MAINDIAL,MAINBACK);
}
break;
case MAINMORE:
if (slc<(2*sld))
{
++slc;
rs_object[rs_trloc[MAINDIAL]+MAINSLID].ob_x=slc;
dial_draw(MAINDIAL,MAINBACK);
}
break;
case MAINQUIT:
break;
}
}
erase_dialog(x,y,w,h);
if (buf!=NULL)
free(buf);
}
graf_mouse(ARROW,0);
appl_exit();
return(0);
}